﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;

using Kwan.Data;
using BG.Data;

namespace BG.Service
{
    public class UserQuery
	{

		public static Expression MakeSearchWhere(NameValueCollection ps)
		{
			Expression exp = new Expression();

            string propName = "EntityID";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TUser.entityID == ps[propName];

			propName = "answer";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TUser.answer == ps[propName];
			}
			propName = "discount";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TUser.discount == int.Parse(ps[propName]);
			}
			propName = "email";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TUser.email == ps[propName];
			}
            propName = "scale";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
                exp &= TUser.scale == int.Parse(ps[propName]);
			}
			propName = "loginCount";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TUser.loginCount == int.Parse(ps[propName]);
			}
			propName = "loginTime";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TUser.loginTime == DateTime.Parse(ps[propName]);
			}
			propName = "logo";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TUser.logo == ps[propName];
			}
			propName = "name";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TUser.name == ps[propName];
			}
			propName = "password";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TUser.password == ps[propName];
			}
			propName = "question";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TUser.question == ps[propName];
			}
			propName = "roleID";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TUser.roleID == ps[propName];
			}
			propName = "userName";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TUser.userName == ps[propName];
			}

			return exp;
		}
	}
}